<template>
  <el-dialog
    width="90%"
    :title="$t('可用库存')"
    destroy-on-close
    append-to-body
    :visible.sync="show"
    :before-close="cancel"
  >
    <el-table :height="calTableHeight() - 150" v-loading="loading" ref="TableRef" :data="tableData" row-key="menuId">
      <el-table-column :label="$t('申请者')" prop="applyName" align="center" width="150" />
      <!-- sku -->
      <el-table-column align="center" width="110" show-overflow-tooltip prop="skuNo" :label="$t('sku编号')">
        <template slot-scope="scope">
          <div style="cursor: pointer; color: #1890ff">
            {{ scope.row.skuNo }}
          </div>
        </template>
      </el-table-column>
      <!-- 主图 -->
      <el-table-column :label="$t('主图')" prop="imgUrl" align="center">
        <template slot-scope="scope">
          <el-image
            fit="contain"
            :key="Math.random()"
            v-hover="scope.row.imgUrl"
            style="width: 50px; height: 50px"
            :src="scope.row.imgUrl + '?x-oss-process=image/resize,w_100/quality,q_70'"
          />
        </template>
      </el-table-column>
      <!-- 申请时价格 -->
      <el-table-column :label="$t('申请时价格')" prop="applyPrice" align="center" width="110">
        <template slot-scope="scope">
          {{ (+scope.row.applyPrice).toFixed() }}
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="applyNum" :label="$t('申请数量')" />
      <el-table-column align="center" show-overflow-tooltip prop="useNum" width="110">
        <template #header>
          <span>
            <el-tooltip placement="top">
              <template #content>
                <p>包裹生成前的可用数量，包裹生成后就会扣除对应的数量</p>
              </template>
              <i class="el-icon-question" style="cursor: pointer; color: #409eff"></i>
            </el-tooltip>
          </span>
          <span>{{ $t('剩下可用数量') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="saleNum" :label="$t('出售数量')" width="110">
        <template #header>
          <span>
            <el-tooltip placement="top">
              <template #content>
                <p>卖了多少个了，库存出库后计算数量</p>
              </template>
              <i class="el-icon-question" style="cursor: pointer; color: #409eff"></i>
            </el-tooltip>
          </span>
          <span>{{ $t('出售数量') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="waitBillNum" :label="$t('待出账单数量')" width="110">
        <template #header>
          <span>
            <el-tooltip placement="top">
              <template #content>
                <p>有多少个账单没生成的，生成了账单不代表已经付款了</p>
              </template>
              <i class="el-icon-question" style="cursor: pointer; color: #409eff"></i>
            </el-tooltip>
          </span>
          <span>{{ $t('待出账单数量') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="payNum" :label="$t('付款数量')" width="110">
        <template #header>
          <span>
            <el-tooltip placement="top">
              <template #content>
                <p>付款数量大于申请数量的50%才能继续申请</p>
              </template>
              <i class="el-icon-question" style="cursor: pointer; color: #409eff"></i>
            </el-tooltip>
          </span>
          <span>{{ $t('付款数量') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" width="80" prop="offlineStatus" :label="$t('线下支付审核状态')">
        <template slot-scope="{ row }">
          <span v-if="row.offlineStatus == 1">
            <!-- 待审核 -->
            {{ $t('审核中') }}
          </span>
          <span style="color: green" v-if="row.offlineStatus == 2">
            <!-- 审核通过 -->
            {{ $t('已确定') }}
          </span>
          <span style="color: red" v-if="row.offlineStatus == 3">
            <!-- 审核不通过 -->
            {{ $t('取消') }}
          </span>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip :label="$t('申请通过状态')" align="center" prop="applyStatus" width="110">
        <template slot-scope="scope">
          <span v-if="scope.row.applyStatus == 1" style="color: red">
            {{ $t('待审批') }}
          </span>
          <span v-else-if="scope.row.applyStatus == 2 && scope.row.backNum == 0" style="color: rgb(86, 143, 0)">
            {{ $t('审批通过') }}
          </span>
          <span
            v-else-if="scope.row.applyNum > scope.row.backNum && scope.row.backNum != 0"
            style="color: rgb(143, 134, 0)"
          >
            {{ $t('部分退回') }}
          </span>
          <span v-else-if="scope.row.applyNum == scope.row.backNum" style="color: rgb(2, 0, 143)">
            {{ $t('全部退回') }}
          </span>
          <span v-else-if="scope.row.applyStatus == 3" style="color: #c0c4cc; cursor: pointer">
            {{ $t('拒绝') }}
          </span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip :label="$t('付款完成状态')" align="center" prop="payStatus" width="110">
        <template slot-scope="scope">
          <!-- 0：未支付 1：部分支付 2：支付完成 -->
          <span v-if="scope.row.payStatus == 0" style="color: red">
            {{ $t('未支付') }}
          </span>
          <span v-else-if="scope.row.payStatus == 1" style="color: red">
            {{ $t('部分支付') }}
          </span>
          <span v-else-if="scope.row.payStatus == 2" style="color: rgb(86, 143, 0)">
            {{ $t('支付完成') }}
          </span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip :label="$t('退回数量')" align="center" prop="backNum" />
      <el-table-column show-overflow-tooltip :label="$t('申请日期')" align="center" prop="applyTime" />
      <!-- <el-table-column show-overflow-tooltip :label="$t('所属者')" align="center" prop="applyDistrName" /> -->
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div slot="footer">
      <el-button @click="cancel">
        {{ $t('关闭') }}
      </el-button>
    </div>
  </el-dialog>
</template>
<script>
// import { api } from '@/api/**'
import { getSkuSellerApplyList } from '@/api/distribution/sku/SellerSku'
export default {
  props: {
    /**
     * formData
     */
    formData: {
      type: Object,
      default: () => ({}),
    },
    /**
     * type
     */
    type: {
      type: String,
    },
    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      required: true,
      default: false,
    },
  },
  data() {
    return {
      /**表格数据 */
      tableData: [],
      /**总条数 */
      total: 0,
      loading: false,
      /**分页相关查询参数 */
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    }
  },
  computed: {},
  watch: {
    show: function (newValue) {
      if (newValue) {
        this.getList()
      }
    },
  },
  methods: {
    getList() {
      this.loading = true
      getSkuSellerApplyList({
        ...this.queryParams,
        skuSellerId: this.formData.id,
        useNum: 0,
      })
        .then((res) => {
          this.tableData = res.rows
          this.total = res.total
        })
        .finally(() => (this.loading = false))
    },

    cancel() {
      this.$emit('getList')
      this.$emit('update:show', false)
    },
  },
}
</script>
<style scoped lang="scss"></style>
